/*
 * TestFul - http://code.google.com/p/testful/
 * Copyright (C) 2012 Matteo Miraz
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package testful.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * TODO describe me!
 * 
 * @author Administrator
 */
public class TxtLog {
	private SimpleDateFormat dataFormat = new SimpleDateFormat("yyyyMMddHHmmss");
	private BufferedWriter out;
	public static StringBuffer logs = new StringBuffer();

	public void log() {
		try {
			// initial the output stream and the output file
			out = new BufferedWriter(new FileWriter(System.currentTimeMillis()
					+ "-log.txt"));

			out.write(logs.toString());
			out.write("\n");
			out.close();

		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("File error.");
		}
	}

	/**
	 * output the result
	 */
	public void outputCSV() {
		Date now = new Date();

		String path = Cache.config.getCut().replace('.', File.separatorChar);
		try {
			FileWriter fw = new FileWriter(Cache.config.getDirGeneratedTests()
					+ "" + File.separatorChar + path + "-"
					+ dataFormat.format(now) + "-" + Cache.improvement + ".csv");
			String header = "CoverageBranch,CoverageBasicBlocks,CoveragePUse,CoverageDataFlow,CoverageDefExp,FaultsCoverage\r\n";
			fw.write(header);

			fw.write(Cache.experiment.toString());
			fw.flush();

			fw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
